Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System
Imports System.Data
Imports GTSDAL
Imports GTSDALTableAdapters
Namespace GTSSystem.BLL
    <System.ComponentModel.DataObject()> _
        Public Class RateLocation

        Private _RateLocationAdaptor As RateLocationTableAdapter = Nothing

        Protected ReadOnly Property RateLocationAdaptor() As RateLocationTableAdapter
            Get
                If _RateLocationAdaptor Is Nothing Then
                    _RateLocationAdaptor = New RateLocationTableAdapter
                End If
                Return _RateLocationAdaptor
            End Get
        End Property

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
        Public Shared Function GetRateLocation(ByVal BranchID As Integer) As RateLocationDataTable

            Try
                Dim RateLocationAdaptor As New GTSDALTableAdapters.RateLocationTableAdapter
                If (BranchID > 0) Then
                    Return RateLocationAdaptor.GetDataByBranchID(BranchID)
                Else
                    Return RateLocationAdaptor.GetDataOfRateLocation
                End If

            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
            Public Function GetRateLocationByRateLocationID(ByVal RateLocationId As Integer) As RateLocationDataTable

            Try
                Return RateLocationAdaptor.GetRateLocationByRateLocationID(RateLocationId)
            Catch ex As Exception
                Throw
            End Try
        End Function


        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Insert, True)> _
        Public Function AddRateLocation(ByVal BranchID As Integer, ByVal City As String, ByVal Province As String, ByVal Country As String) As Integer
            If BranchID = 0 Then
                Dim user As MembershipUser = Membership.GetUser
                Dim p As ProfileCommon = ProfileCommon.Create(user.UserName)
                BranchID = p.BranchId
            End If
            Try
                Return RateLocationAdaptor.Insert(BranchID, City, Province, Country)
            Catch ex As Exception
                Throw
            End Try
        End Function

        <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Update, True)> _
        Public Function UpdateRateLocation(ByVal RateLocationID As Integer, _
                                            ByVal City As String, _
                                            ByVal Province As String, _
                                            ByVal Country As String)
            Dim user As MembershipUser = Membership.GetUser
            Dim p As ProfileCommon = ProfileCommon.Create(user.UserName)
            Try
                Return RateLocationAdaptor.UpdateRateLocation(City, Province, Country, RateLocationID, p.BranchId)
            Catch ex As Exception
                Throw
            End Try
        End Function
    End Class

End Namespace